package www.openteam.com.presenter.business;

import java.util.HashMap;

import www.openteam.com.adapter.CustomOrderAdapter;
import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.ApprovalStatu;
import www.openteam.com.bean.DeleteInfo;
import www.openteam.com.bean.DeleteWholeInfo;
import www.openteam.com.contract.business.adapter.EditCustomOrderContract;
import www.openteam.com.model.business.EditCustomOrderModel;
import www.openteam.com.mvp.IModel;

/**
 * Created by kylin on 2016/11/23.
 */

public class EditCustomOrderInfoPresenter extends BasePresenter<CustomOrderAdapter>
        implements EditCustomOrderContract.EditCustomOrderPresenter {


    //更新子订单
    @Override
    public void updateCustomOrderItemInfo(int id, String prodno, String wraptype, String paperinf, String senddate, String technicsinf, String printcolor, String paynumb, String othernumb, String price, String eprodno) {
        ((EditCustomOrderModel) getiModelMap().get("editOrder"))
                .updateCustomOrderItemInfo(id, prodno, wraptype, paperinf, senddate, technicsinf, printcolor
                        , paynumb, othernumb, price, eprodno, new EditCustomOrderModel.
                                UpdateCustomOrderItemInfoOnListener() {
                            @Override
                            public void updateCOIISuccess(ApprovalStatu updateState) {
                                getIView().updateCOMIData(updateState);
                            }

                            @Override
                            public void updateCOIIFail(Throwable throwable) {
                                getIView().hideCOMIData(throwable);
                            }
                        });
    }



    //新建子订单
    @Override
    public void insertCustomOrderItemInfo(int id, String prodno, String wraptype, String paperinf, String senddate, String technicsinf, String printcolor, String paynumb, String othernumb, String price) {

        ((EditCustomOrderModel) getiModelMap().get("editOrder"))
                .insertCustomOrderItemInfo(id, prodno, wraptype, paperinf, senddate, technicsinf, printcolor,
                        paynumb, othernumb, price, new EditCustomOrderModel.
                                InsertCustomOrderItemInfoOnListener() {
                            @Override
                            public void insertCOIISuccess(ApprovalStatu approvalStatu) {
                                getIView().insertCOMIData(approvalStatu);
                            }

                            @Override
                            public void insertCOIIFail(Throwable throwable) {
                                getIView().insertFailData(throwable);
                            }
                        });
    }
    //删除子订单
    @Override
    public void deleteCustomOrderItemInfo(int zbid, String prodno) {
        ((EditCustomOrderModel) getiModelMap().get("editOrder"))
                .deleteCustomOrderItemInfo(zbid, prodno, new EditCustomOrderModel.EditCustomOrderItemInfoOnListener() {
                    @Override
                    public void deleteECOIISuccess(DeleteInfo deleteInfo) {
                        getIView().loadECOIIData(deleteInfo);
                    }

                    @Override
                    public void deleteECOIIFail(Throwable throwable) {
                        getIView().hideECOIIData(throwable);
                    }
                });
    }

    @Override
    public void updateCustomOrderMainInfo(int id, String rdsno, String custid, String userid, String moneytype, String paytime, String sendtype, String custorderid, String alreadlypay, String inputdate, String inputer, String orderamount, String remark, String orderdate, String sendaddress, String istax, String taxrate, String invtype, String stype) {
        ((EditCustomOrderModel) getiModelMap().get("editOrder"))
                .updateCustomOrderMainInfo(id, rdsno, custid, userid, moneytype, paytime, sendtype,
                        custorderid, alreadlypay, inputdate, inputer, orderamount, remark, orderdate,
                        sendaddress, istax, taxrate, invtype, stype, new EditCustomOrderModel.UpdateCustomOrderInfoOnListener() {
                            @Override
                            public void updateCOISuccess(ApprovalStatu updateState) {
                                getIView().updateCOIData(updateState);
                            }

                            @Override
                            public void updateCOIFail(Throwable throwable) {
                                getIView().hideCOIData(throwable);
                            }
                        });
    }


    @Override
    public void deleteCustomOrderInfo(int id) {
        ((EditCustomOrderModel) getiModelMap().get("editOrder"))
                .deleteCustomOrderInfo(id, new EditCustomOrderModel.EditCustomOrderInfoOnListener() {
                    @Override
                    public void deleteECOISuccess(DeleteWholeInfo deleteInfo) {

                        getIView().loadDCOIData(deleteInfo);
                    }

                    @Override
                    public void deleteECOIFail(Throwable throwable) {
                        getIView().hideDCOIData(throwable);
                    }
                });


    }


    @Override
    public HashMap<String, IModel> getiModelMap() {

        return loadModelMap(new EditCustomOrderModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("editOrder", models[0]);
        return hashMap;
    }
}
